package com.dcbeida.model;

import com.dcbeida.MyApplication;
import com.dcbeida.utils.GenApiHashUrl;
import com.dcbeida.utils.JsonGet;

import dc.medicine.com.okhttplib.OkHttpUtils;
import dc.medicine.com.okhttplib.callback.AbsCallback;

/**
 * Created by hp on 2016/7/27.
 */
public class InventoryModel {

    private static InventoryModel mInventoryModel;

    private InventoryModel() {

    }

    public static InventoryModel newInstance() {
        if (mInventoryModel == null) {
            return new InventoryModel();
        } else {
            return mInventoryModel;
        }
    }

    public void getCountDate(AbsCallback mAbsCallback) {
        OkHttpUtils.getInstance().post(GenApiHashUrl.apiUrl).tag(this)
                .paramsApp("service", "getdruginfo")
                .paramsApp("params", new JsonGet().putopt("uid", MyApplication.user.getUid()).putopt("drugid", "0").tostring()).execute(mAbsCallback);
    }


    public void getDrugDetailDate(String drugcode, AbsCallback mAbsCallback) {
        OkHttpUtils.getInstance().post(GenApiHashUrl.apiUrl).tag(this)
                .paramsApp("service", "getdrugcodeinfo")
                .paramsApp("params", new JsonGet().putopt("drugcode", drugcode).putopt("uid", MyApplication.user.getUid()).tostring()).execute(mAbsCallback);
    }


    public void addinventorydrugcodes(String drugcode, AbsCallback mAbsCallback) {
        OkHttpUtils.getInstance().post(GenApiHashUrl.apiUrl).tag(this)
                .paramsApp("service", "addinventorydrugcodes")
                .paramsApp("params", new JsonGet().putopt("drugcodes", drugcode).putopt("uid", MyApplication.user.getUid()).tostring()).execute(mAbsCallback);
    }


    public void updatestockinlog(String stockinlogid,String from,String fromId,String invoicemoney, AbsCallback mAbsCallback) {
        OkHttpUtils.getInstance().post(GenApiHashUrl.apiUrl).tag(this)
                .paramsApp("service", "updatestockinlog")
                .paramsApp("params",
                        new JsonGet().putopt("stockinlogid", stockinlogid).
                                putopt("from", from).
                                putopt("fromid", fromId).
                                putopt("invoicemoney", invoicemoney).
                        putopt("uid", MyApplication.user.getUid()).tostring()).execute(mAbsCallback);
    }


    /**
     * 7.	盘点-新增盘点记录
     * @param drguid 药品ID
     * @param quantity 盘点总数量
     * @param mAbsCallback
     */
    public void addInventory(int drguid,int quantity ,AbsCallback mAbsCallback) {
        OkHttpUtils.getInstance().post(GenApiHashUrl.apiUrl).tag(this)
                .paramsApp("service", "addinventory")
                .paramsApp("params", new JsonGet().putopt("uid", MyApplication.user.getUid()).putopt("drugid", drguid).putopt("quantity", quantity).tostring()).execute(mAbsCallback);
    }


    public void getCancel() {
        OkHttpUtils.getInstance().cancelTag(this);
    }
}
